package com.quan.system.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.quan.common.biz.support.BaseService;
import com.quan.system.entity.SystemOssConfig;
import com.quan.system.service.SystemOssConfigService;

/**
 * <p>
 * 系统管理-OSS配置 服务实现类
 * </p>
 *
 * @author 杨浩泉
 * @since 2018-07-05
 */
@Service
public class SystemOssConfigServiceImpl extends BaseService<SystemOssConfig> implements SystemOssConfigService {
	
	@CachePut(cacheNames = "oss", key = "#entity.ossName")
	@Override
	public SystemOssConfig inserOrUpdataOssConfig(SystemOssConfig entity) {
		SystemOssConfig where = new SystemOssConfig() ;
		where.setOssName(entity.getOssName());
		SystemOssConfig ossConfig = super.selectOne(where) ;
		
		if(null != ossConfig) { //修改
			SystemOssConfig config = new SystemOssConfig() ;
			BeanUtils.copyProperties(entity, config);
			super.updateSelective(config);
			return config ;
		} else { //新增
			return super.insertSelective(entity) ;
		}
	}
	
	
	@Cacheable(cacheNames = "oss", key="#ossName")
	@Override
	public SystemOssConfig findByOssName(String ossName) {
		SystemOssConfig entity = new SystemOssConfig() ;
		entity.setOssName(ossName);
		return super.selectOne(entity) ;
	}

	
}